<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(s, index) in carousel" :key="index">
        <img :src="s.pic" alt="" srcset="" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <!-- <div class="swiper-pagination"></div> -->
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/css/swiper.min.css";
import { getHomepage } from "@/api/api.js";
export default {
  name: "Carousel",
  data() {
    return {
      carousel: "",
    };
  },
  created() {
    getHomepage().then((response) => {
      this.carousel = response.data.data.blocks[0].extInfo.banners;
      console.log(response.data.data.blocks[0].extInfo.banners);
    });
  },
  updated() {
    var mySwiper = new Swiper(".swiper-container", {
      //direction: 'vertical', // 垂直切换选项
      loop: true, // 循环模式选项

      // 如果需要分页器
      pagination: {
        el: ".swiper-pagination",
      },

      // 如果需要前进后退按钮
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },

      // 如果需要滚动条
      scrollbar: {
        el: ".swiper-scrollbar",
      },
      autoplay: {
        pauseOnMouseEnter: true,
        disableOnInteraction: false,
      },
    });
  },
};
</script>

<style scoped>
.swiper-container {
  width: 850px;
  height: 300px;
}
img {
  width: 100%;
}
</style>
